home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Unca Fenster / Source / FinderToFSSpec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  2.8 KB  |  86 lines  |  [TEXT/KAHL]

  1. #include <Folders.h>
  2. #include "FinderToFSSpec.h"
  3.  
  4. void FindName(FinderHandle fh, StringPtr name)
  5. {
  6.     int i;
  7.     Boolean    gotName = FALSE;
  8.     
  9.     // (* find where the name starts by looking for “$0BEA” in the Finder™’s object handle *)
  10.  
  11.     for (i=0; i<=GetHandleSize((Handle)fh)-2; i++) {
  12.         if (!gotName) {
  13.             gotName = (((*(unsigned char **)fh)[i] == 0x0B) && ((*(unsigned char **)fh)[i+1] == 0xEA));
  14.             if (gotName)
  15.                 break;
  16.         }
  17.     }
  18.  
  19.     if (gotName)
  20.         BlockMove((((Ptr)(*fh))+i+4), name, 32);
  21.     else
  22.         name[0] = 0;
  23. }
  24.  
  25. void FinderHandleToFSSpec(FinderHandle fh, FSSpecPtr f)
  26. {
  27.     short         i, tvrefnum, dvrefnum;
  28.     Boolean        b;
  29.     long        tdirid, ddirid;
  30.     CInfoPBRec    cipb;
  31.  
  32.     i = FindFolder(kOnSystemDisk, kTrashFolderType, kDontCreateFolder, &tvrefnum, &tdirid);
  33.     i = FindFolder(kOnSystemDisk, kDesktopFolderType, kDontCreateFolder, &dvrefnum, &ddirid);
  34.  
  35.     f->vRefNum = (*fh)->fvRefNum;
  36.     /*
  37.     (* the Finder™ normally stores the parent directory in the “fparenth” field of the FinderHandle. But if the file/folder is in the *)
  38.     (* “Desktop Folder” then the “fdirID” may not be valid for the given “fvRefNum”. We check if “fvRefNum” matches and if not *)
  39.     (* then we use the alternative method - actually what the Finder™ also uses! *)
  40.     */
  41.     if ((*fh)->fDirID == 2) 
  42.         f->parID = 1;
  43.     else if (((*fh)->fvRefNum == tvrefnum) && ((*fh)->fDirID == tdirid)) {
  44.         /*
  45.         (* special case for the Trash. This icon sits on the Finder™ desktop and has to be taken into account. We check for the same *)
  46.         (* “fvRefNum” and “fDirID”. If these match then get the name for the folder from a _GetCatInfo and Exit(FinderHandleToFSSpec *)
  47.         */
  48.  
  49.         cipb.hFileInfo.ioCompletion = 0L;
  50.         cipb.hFileInfo.ioNamePtr = (StringPtr)f->name;
  51.         cipb.hFileInfo.ioVRefNum = f->vRefNum;
  52.         cipb.hFileInfo.ioDirID = tdirid;
  53.         cipb.hFileInfo.ioFDirIndex = -1;
  54.         i = PBGetCatInfoSync(&cipb);
  55.         f->parID = cipb.dirInfo.ioDrParID;
  56.         return;
  57.     }
  58.     else if (((*fh)->fvRefNum == dvrefnum) && ((*fh)->fDirID == ddirid)) {
  59.         cipb.hFileInfo.ioCompletion = 0L;
  60.         cipb.hFileInfo.ioNamePtr = (StringPtr)f->name;
  61.         cipb.hFileInfo.ioVRefNum = f->vRefNum;
  62.         cipb.hFileInfo.ioDirID = ddirid;
  63.         cipb.hFileInfo.ioFDirIndex = -1;
  64.         i = PBGetCatInfoSync(&cipb);
  65.         f->parID = cipb.dirInfo.ioDrParID;
  66.         return;
  67.     }
  68.     else {
  69.         if ((*(**fh).fParentH)->fvRefNum != f->vRefNum) {
  70.             if (((*fh)->fvRefNum == tvrefnum) && ((*fh)->fDirID = tdirid)) 
  71.                 i = FindFolder(f->vRefNum, kTrashFolderType, kDontCreateFolder, &tvrefnum, &f->parID);
  72.             else if (((*fh)->fvRefNum == dvrefnum) && ((*fh)->fDirID == ddirid))
  73.                 i = FindFolder(f->vRefNum, kDesktopFolderType, kDontCreateFolder, &dvrefnum, &f->parID);
  74.             else if ((*(*fh)->fMainDirH)->fDesktopH != 0L) 
  75.                 f->parID = (*(*(*fh)->fMainDirH)->fDesktopH)->fDirID;
  76.             else
  77.                 f->parID = -1;
  78.         }
  79.         else {
  80.             f->parID = (*(*fh)->fParentH)->fDirID;
  81.         }
  82.     }
  83.     
  84.     FindName(fh, f->name);
  85. }
  86.